// components/after-sale-goods-item/after-sale-goods-item.js
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    //订单结算页
    paymentItem: {
      type: Object,
      value: '',
      observer(newVal, oldVal, changedPath) {
        if (newVal) {
          this.initData(newVal);
        }
      }
    },
    //订单详情
    orderDetailItem: {
      type: Object,
      value: '',
      observer(newVal, oldVal, changedPath) {
        if (newVal) {
          this.initOrderDetailData(newVal);
        }
      }
    },
    //售后订单详情
    item: {
      type: Object,
      value: '',
      observer(newVal, oldVal, changedPath) {
        if (newVal) {
          this.initOrderDetailData(newVal);
        }
      }
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    currentItem: null,
    promotionPrice: '', //促销价格
    price: '', //原价
  },

  /**
   * 组件的方法列表
   */
  methods: {
    //初始化数据
    initData: function (item) {
      let tmpPromotionPrice = '';
      let tmpPrice = '';

      if (item.type == 0) {
        //只有原价
        tmpPromotionPrice = item.minPrice;
        tmpPrice = item.minCrossedPrice;
      } else {
        //促销或者团购的话有原价和促销价
        tmpPromotionPrice = item.promotionPrice;
        tmpPrice = item.price;
      }

      this.setData({
        promotionPrice: tmpPromotionPrice,
        price: tmpPrice,
        currentItem: item
      });
    },
    //初始化订单详情数据
    initOrderDetailData: function (item) {
      let tmpPromotionPrice = '';
      tmpPromotionPrice = item.price;

      this.setData({
        promotionPrice: tmpPromotionPrice,
        currentItem: item
      });
    }
  }
})